<template>
  <van-nav-bar
    :title="title"
    fixed
    :right-text="rightText"
    left-arrow
    @click-left="leftClick"
    @click-right="rightClick"
  />
</template>

<script lang="ts" setup name="nav-bar">
import { useRouter } from 'vue-router'
const router = useRouter()
// 使用组件时候才能确定的功能：标题，右侧文字，点击右侧文字行为（props传入）
const props = defineProps<{
  title?: string
  rightText?: string
  rightClick?: () => void
  back?: () => void
}>()
const leftClick = () => {
  if (props.back) {
    props.back()
  } else {
    // 返回
    router.back()
  }
}
</script>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
